from fastapi.middleware.cors import CORSMiddleware
from starlette.middleware import authentication
from starlette.requests import HTTPConnection
from starlette.responses import PlainTextResponse, Response


class AuthenticationMiddleware(authentication.AuthenticationMiddleware):
    @staticmethod
    def default_on_error(conn: HTTPConnection, exc: Exception) -> Response:
        return PlainTextResponse(exc.msg, status_code=exc.status_code)
